import Vue from 'vue'
import VueRouter from 'vue-router'
import Home from '@/views/Home'
import tableRouter from './modules/tableRouter'
import productRouter from './modules/productRouter'
import deviceRouter from './modules/deviceRouter'
// import scrollintoviewRouter from './modules/scollIntoViewRouter'
Vue.use(VueRouter)

/**
 * constantRoutes 公共路由
 * 没有权限要求的基本页面
 * 所有角色都能访问
 */
const constantRoutes = [
  {
    path: '/',
    name: 'Home',
    component: Home
  },
  {
    path: '/about',
    name: 'About',
    // route level code-splitting
    // this generates a separate chunk (about.[hash].js) for this route
    // which is lazy-loaded when the route is visited.
    component: () => import(/* webpackChunkName: "about" */ '../views/About')
  },
  {
    path: '/scrollintoview',
    name: 'ScrollIntoView',
    // route level code-splitting
    // this generates a separate chunk (about.[hash].js) for this route
    // which is lazy-loaded when the route is visited.
    component: () =>
      import(/* webpackChunkName: "about" */ '../views/ScrollIntoView')
  },
  {
    path: '/401',
    component: resolve => require(['@/views/error/401'], resolve),
    hidden: true
  },
  {
    path: '/404',
    component: resolve => require(['@/views/error/404'], resolve),
    hidden: true
  }
  // {
  //   path: '/table/base-table',
  //   component: (resolve) => require(['@/views/table/BaseTable'], resolve),
  //   hidden: true
  // },
]

const errorRoutes = [
  {
    path: '*',
    // redirect: '/404',
    component: resolve => require(['@/views/error/404'], resolve),
    name: 'Page404',
    hidden: true
  }
]

/**
 * asyncRoutes 异步路由
 * 需要根据用户角色动态加载的路由
 */
export const asyncRoutes = [tableRouter, ...productRouter, ...deviceRouter]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes: constantRoutes
})

router.addRoutes(asyncRoutes)
router.addRoutes(errorRoutes) // 通配路由一定要放到最后

export default router
